package org.nidy.programexercise.ThreadExercise;

public class Producer extends Thread{
    @Override
    public void run() {
        while (true){
            synchronized (Intermediary.lock){
                if(Intermediary.count==0) {
                    break;
                }else{
                    if(Intermediary.flag==1){
                        try {
                            Intermediary.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }else{
//                        Intermediary.count--;
                        System.out.println("生产者生产了1个产品");
                        Intermediary.flag=1;
                        Intermediary.lock.notify();
                    }
                }
            }
        }
    }
}
